<template>
  <div>
    <el-table v-loading="loading" :data="noticeList">
      <el-table-column label="序号" align="center" width="50" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.order || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="标题" align="center" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.title || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="经验分类" align="center" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.experienceTypeName || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="链接记录" align="center" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <el-button type="text" @click="routerlink(scope.row)">{{ scope.row.sourceCode || '-' }}</el-button>
          <!-- <dict-tag :options="statusFlag" :value="scope.row.status" /> -->
        </template>
      </el-table-column>
      <el-table-column label="问题描述" align="center" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <!-- <el-link :disabled="!scope.row.file" :href="scope.row.file" target="_blank" type="primary">{{
            scope.row.fileName || '-'
          }}</el-link> -->
          {{ scope.row.faultDescribe || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="保养标准" align="center" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <div v-for="(v, i) in scope.row.upkeepTypeList" :key="i">
            {{ v.typeName || '-' }}
            <template v-if="scope.row.upkeepTypeList && scope.row.upkeepTypeList.length - 1 !== i">,</template>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="描述" align="center" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.remark || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="创建用户" align="center" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.createBy || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.createTime || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="修改用户" align="center" min-width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.updateBy || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="修改日期" align="center" min-width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.updateTime || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="操作" min-width="200" fixed="right" align="center" class-name="medium-padding fixed-width">
        <template slot-scope="scope">
          <el-button :disabled="scope.row.sourceCode !== null" size="small" v-hasPermi="['draftbase_xg']" type="primary"
            icon="el-icon-edit" @click="handleUpdate(scope.row)">编辑</el-button>
          <!-- <el-button v-hasPermi="['project_dis']" v-if="scope.row.status === '0'" icon="el-icon-lock" size="small"
            type="danger" @click="handleDis(scope.row)">禁用
          </el-button>
          <el-button v-hasPermi="['project_dis']" v-else size="small" type="success" icon="el-icon-unlock"
            @click="handleDis(scope.row)">启用
          </el-button> -->
          <el-button :disabled="scope.row.sourceCode !== null" v-hasPermi="['draftbase_sc']" icon="el-icon-delete"
            size="small" type="danger" @click="handleDelete(scope.row)">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- <div class="card-div"> -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <!-- </div> -->
    <template v-if="open">
      <AddbaseValue :title="title" :rowObj="rowObj"></AddbaseValue>
    </template>
  </div>
</template>

<script>
import { getbaseList, deletedbase, UpdateinspectionStatus } from "@/api/knowledge/draftbase.js";

export default {
  components: {
    AddbaseValue: () => import('../form/addbaseValue'),
  },
  data () {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      dictdatalist: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 弹出层表格数据
      noticeList: [],
      rowObj: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderByColumn: 'id',
        // isAsc: 'asc'//正叙
        isAsc: 'desc'//倒叙
      },
    };
  },
  created () {
    this.getList();
  },
  methods: {
    routerlink (row) {
      if (row.sourceType === '2') {//保养任务
        this.$tab.openPage('保养任务', '/maintenance/insurance/Task', { sourceId: row.sourceId })//保养任务
      } else if (row.sourceType === '1') {//维修工单
        this.$tab.openPage('维修工单', '/maintenance/management/guysingle', { sourceId: row.sourceId })//维修工单
      } else {
        return false
      }
    },
    /** 查询列表 */
    async getList (value) {
      this.loading = true;
      let params = {
        ...this.queryParams,
        ...value
      }
      getbaseList(params).then(response => {
        this.noticeList = response.data && response.data.map((item, index) => {
          return {
            ...item,
            order: index + 1
          }
        });
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 修改按钮操作 */
    handleUpdate (row) {
      this.rowObj = row
      this.open = true
      this.title = '修改经验'
    },
    /** 启用禁用按钮操作 */
    handleDis (row) {
      this.$confirm(`是否确认${row.planStatus === '0' ? `禁用` : `启用`}该的数据？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true;
        let params = {
          id: row.id,
          status: row.status === '0' ? 1 : 0
        }
        UpdateinspectionStatus(params).then(res => {
          if (res.code === 200) {
            this.loading = false;
            this.$message.success(res.msg)
            this.getList()
          }
        }).catch(() => { this.loading = false; });
      }).catch(() => { this.loading = false; });
    },
    handleDelete (row) {
      this.$confirm(`是否确认删除该经验？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true;
        deletedbase(row.id).then(res => {
          if (res.code === 200) {
            this.$message.success(res.msg)
            this.getList()
          }
          this.loading = false;
        }).catch(() => { this.loading = false; });
      }).catch(() => { this.loading = false; });
    }
  },
  filters: {
  }
};
</script>
<style lang="scss" scoped>
.red {
  color: red;
}
</style>